local zhaoran = fk.CreateSkill{
    name = "jin_heg__zhaoran",
}

Fk:loadTranslationTable{
    ["jin_heg__zhaoran"] = "昭然",
    [":jin_heg__zhaoran"] = "出牌阶段开始时，你可摸X张牌（X为4-场上非野心家势力数），然后未确定势力的角色依次选择是否明置一张武将牌并令你结束此回合。",

    ["#jin_heg__zhaoran-ask"] = "昭然：是否明置一张武将牌，令 %src 结束此回合？",

    ["$jin_heg__zhaoran1"] = "行昭然于世，赦众贼以威。",
    ["$jin_heg__zhaoran2"] = "吾之心思，路人皆知。",
}

local H = require "packages.ol_hegemony.util"

zhaoran:addEffect(fk.EventPhaseChanging, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhaoran.name) and
      data.phase == Player.Play and not data.skipped
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local kingdoms = {}
    for _, p in ipairs(table.filter(room.alive_players, function(p) return p.kingdom ~= "unknown" and p.kingdom ~= "wild" end)) do
     table.insertIfNeed(kingdoms, H.getKingdom(p))
    end
    local n = math.max(0, 4 - #kingdoms)
    player:drawCards(n, zhaoran.name)
    if player.dead then return end
    for _, p in ipairs(room:getAlivePlayers()) do
      if not p.dead and p.kingdom == "unknown" and
      H.askToRevealGenerals(p, {
        skill_name = zhaoran.name,
        prompt = "#jin_heg__zhaoran-ask:"..player.id,
        revealAll = false,
      }) ~= "Cancel" then
        data.skipped = true
        room:endTurn()
        break
      end
    end
  end,
})

return zhaoran